'use strict';

const Controller = require('egg').Controller;

class OrderController extends Controller {
  async createOrder() {
    const params = this.ctx.request.body;
    const result = await this.ctx.service.order.createOrder(
        params.rid,
        params.tid,
        params.dids,
        params.total,
        params.openId
    );
    if(result !== 'error'){
        this.ctx.code = 200;
    }else{
        this.ctx.code = 301;
    }
    this.ctx.body = result;
  }

  async orderRecord(){
      const params = this.ctx.request.query;
      const result = await this.ctx.service.order.orderRecord(params.openid,params.paystatus);
      if(result === 'error'){
          this.ctx.code = 301;
      }else{
          this.ctx.code = 200;
      }
      this.ctx.body = result;
  }

  async orderDetail(){
      const billcode = this.ctx.request.query.billcode;
      const result = await this.ctx.service.order.recordDetail(billcode);
      if(result === 'error'){
          this.ctx.code = 301;
      }else{
          this.ctx.code = 200;
      }
      this.ctx.body = result;
  }
}

module.exports = OrderController;
